﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using StoreManagement.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace StoreManagement.ViewModel
{
    public class EditGoodsTypeViewModel : ViewModelBase
    {
        private GoodsType goodsType = new GoodsType();
        public GoodsType GoodsType
        {
            get { return goodsType; }
            set { goodsType = value; RaisePropertyChanged(); }
        }

        //修改
        public RelayCommand<Window> EditCommand
        {
            get
            {
                var command = new RelayCommand<Window>((window) =>
                {
                    if (string.IsNullOrEmpty(GoodsType.Name) == true)
                    {
                        MessageBox.Show("不能为空");
                        return;
                    }

                    var service = new GoodsTypeService();
                    int count = service.Update(GoodsType);
                    if (count > 0)
                    {
                        MessageBox.Show("修改成功");
                        window.Close();
                    }
                    else
                    {
                        MessageBox.Show("修改失败");
                    }
                });

                return command;
            }
        }
    }
}
